package com.itnoob.controller;


import com.itnoob.service.PayService;
import com.itnoob.type.PayTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author zhoujun
 * @date 2024/12/5 22:19
 */
@RestController
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private PayService payService;

    /**
     * localhost:8080/strategy/pay?amount=100&type=wechat
     * @param amount
     * @param payType 1-->WECHAT_PAY  2-->ALI_PAY
     * @return
     */
    @RequestMapping("/pay/{payType}/{amount}")
    public String pay( @PathVariable("payType") String  payType,
                       @PathVariable("amount") BigDecimal amount) throws InterruptedException {

        PayTypeEnum payTypeEnum = PayTypeEnum.fromPayTypeEnum(payType);
        System.out.println("当前线程=" + Thread.currentThread().getName() + "支付类型=" + payTypeEnum.getValue().toString());
        Thread.sleep(2000);

        //设置当前线程的支付方式
        payService.setPayTypeEnum(payTypeEnum);
        payService.pay(amount);

        return "支付成功!";

    }



}
